﻿using UnityEngine;
using System.Collections;
using Dict.Config;

namespace Battle
{
    public class FieldPVPBalance : BalanceBase
    {
        public UILabel todayKill;
        public UILabel todayBeKillBefore;
        public UILabel todayBeKillAfter;
        public UILabel GetCoinText;
        public UILabel GetCoin;


        public UILabel GetCoinBig;
        #region lost
        public UITexture lefthero, lefthero0;
        public UITexture righthero, righthero0;

        public UILabel leftName, leftName0;
        public UILabel rightName, rightName0;
        #endregion
        protected override void Refresh()
        {
            base.Refresh();
            SetHero();
            SetLabel();
        }

        public override void Exit()
        {
            base.Exit();
            ManagerController.Instance.BattleToField();
            GameObject.Destroy(gameObject);
        }

        void SetHero()
        {
            var side = StaticData.sidePvpMv;

            var leftDictHero = Dict.Blo.DictHeroBlo.GetTableHero(side.attHeroId);
            var rightDictHero = Dict.Blo.DictHeroBlo.GetTableHero(side.defHeroId);

            //lost
            lefthero.GetComponent<UI.TextureKit>().iconType = UI.TextureIcon.HERO;
            lefthero.GetComponent<UI.TextureKit>().textureName = leftDictHero.iconName;
            righthero.GetComponent<UI.TextureKit>().iconType = UI.TextureIcon.HERO;
            righthero.GetComponent<UI.TextureKit>().textureName = rightDictHero.iconName;

            //win
            lefthero0.GetComponent<UI.TextureKit>().iconType = UI.TextureIcon.HERO;
            lefthero0.GetComponent<UI.TextureKit>().textureName = leftDictHero.iconName;
            righthero0.GetComponent<UI.TextureKit>().iconType = UI.TextureIcon.HERO;
            righthero0.GetComponent<UI.TextureKit>().textureName = rightDictHero.iconName;

            if (side.attPlayerName == StaticData.playerData.name)//攻击者
            {
                

                if (side.attPlayerName == side.winPlayerName)
                {
                    righthero.material = AssetLoad.ResourceManager.Instance.LoadResource("shaders/heroIcon_circle_colorness") as Material;
                    righthero.material.shader = Shader.Find("Unlit/Masked DJMaskColorless");
                }
                else
                {
                    lefthero.material = AssetLoad.ResourceManager.Instance.LoadResource("shaders/heroIcon_circle_colorness") as Material;
                    lefthero.material.shader = Shader.Find("Unlit/Masked DJMaskColorless");
                }
            }
            else
            {
                

                if (side.defPlayerName != side.winPlayerName)
                {
                    righthero.material = AssetLoad.ResourceManager.Instance.LoadResource("shaders/heroIcon_circle_colorness") as Material;
                    righthero.material.shader = Shader.Find("Unlit/Masked DJMaskColorless");
                }
                else
                {
                    lefthero.material = AssetLoad.ResourceManager.Instance.LoadResource("shaders/heroIcon_circle_colorness") as Material;
                    lefthero.material.shader = Shader.Find("Unlit/Masked DJMaskColorless");
                }
            }
            
        }

        void SetLabel()
        {
            
            int num = 0;
            foreach (var it in StaticData.sidePvpMv.resource)
            {
                if (it.id == TableConst.coin)
                {
                    num += it.num;
                }
            }

            GetCoin.text = num + "";

            todayKill.text = StaticData.fieldData.kills+"";
            todayBeKillBefore.text = StaticData.fieldData.beKills + "";
            todayBeKillAfter.text = StaticData.fieldData.beKills + "";

            if (StaticData.playerData.name == StaticData.sidePvpMv.attPlayerName)
            {
                leftName.text = StaticData.playerData.name;
                rightName.text = StaticData.sidePvpMv.defPlayerName;
                leftName0.text = StaticData.playerData.name;
                rightName0.text = StaticData.sidePvpMv.defPlayerName;

                if (StaticData.sidePvpMv.attPlayerName == StaticData.sidePvpMv.winPlayerName)
                {
                    GetCoinText.text = TableTextBlo.GetText("field_pvp_kill_get");
                    GetCoinBig.text = string.Format(TableTextBlo.GetText("field_pv_def_detail_succ"), num);
                }
                else
                {
                    GetCoinBig.text = TableTextBlo.GetText("field_pvp_att_lost");
                    GetCoinText.text = TableTextBlo.GetText("field_pvp_kill_get");
                }
            }
            else
            {
                leftName.text = StaticData.playerData.name;
                rightName.text = StaticData.sidePvpMv.attPlayerName;
                leftName0.text = StaticData.playerData.name;
                rightName0.text = StaticData.sidePvpMv.attPlayerName;

                if (StaticData.sidePvpMv.winPlayerName == StaticData.sidePvpMv.defPlayerName)
                {
                    GetCoinBig.text = TableTextBlo.GetText("field_pvp_att_succ");
                    GetCoinText.text = TableTextBlo.GetText("field_pvp_kill_lost");
                }
                else
                {
                    GetCoinText.text = TableTextBlo.GetText("field_pvp_kill_lost");
                    GetCoinBig.text = string.Format(TableTextBlo.GetText("field_pv_def_detail_lost"), num);
                    
                }

            }

        }
    }
}